package com.wheel.autoconfigure.dynamicdatasource;/*
 * <h3>Title:wheel-parent系统</h3>
 * <p>Copyright (c) 2019, wnfbx@163.com. All rights reserved.</p>
 * @author wnfbx@163.com
 */

import com.wheel.autoconfigure.dynamicdatasource.loadbalancer.DataSourceLoadBalancer;
import com.wheel.autoconfigure.dynamicdatasource.loadbalancer.RandomDataSourceLoadBalancer;
import com.wheel.autoconfigure.dynamicdatasource.loadbalancer.RoundRobinDataSourceLoadBalancer;
import com.wheel.autoconfigure.dynamicdatasource.processor.DynamicDataSourceDetermineProcessor;
import com.wheel.autoconfigure.dynamicdatasource.processor.NoJTADynamicDataSourceDetermineProcessor;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;

/**
 * <dt>Description:DynamicDataSourceProperties</dt>
 * <dd>动态数据源配置</dd>
 *
 * @author wnfbx@163.com
 * @version 1.0 <i>2019/12/16 18:56</i>
 * @since jdk1.7+
 */
@ConfigurationProperties(DynamicDataSourceProperties.PREFIX)
public class DynamicDataSourceProperties {

    public static final String PREFIX = "spring.datasource.dynamic";
    /**
     * 主据源前缀，支持多个主据源
     */
    private String masterPerfix = "master";
    /**
     * 数据源选择处理器
     */
    private Class<? extends DynamicDataSourceDetermineProcessor> determineProcessor = NoJTADynamicDataSourceDetermineProcessor.class;
    /**
     * 主数据源均衡器
     */
    private Class<? extends DataSourceLoadBalancer> masterBalancer = RoundRobinDataSourceLoadBalancer.class;
    /**
     * 从数据源均衡器
     */
    private Class<? extends DataSourceLoadBalancer> slaveBalancer = RandomDataSourceLoadBalancer.class;
    /**
     * 所有数据源映射配置
     */
    private Map<String, Properties> config = new LinkedHashMap<>();
    /**
     * Druid全局配置
     */
    @NestedConfigurationProperty
    private Properties globalDruidConfig;
    /**
     * HikariCp全局参数配置
     */
    @NestedConfigurationProperty
    private Properties globalHikariConfig;

    public Class<? extends DynamicDataSourceDetermineProcessor> getDetermineProcessor() {
        return determineProcessor;
    }

    public void setDetermineProcessor(Class<? extends DynamicDataSourceDetermineProcessor> determineProcessor) {
        this.determineProcessor = determineProcessor;
    }

    public Class<? extends DataSourceLoadBalancer> getMasterBalancer() {
        return masterBalancer;
    }

    public void setMasterBalancer(Class<? extends DataSourceLoadBalancer> masterBalancer) {
        this.masterBalancer = masterBalancer;
    }

    public Class<? extends DataSourceLoadBalancer> getSlaveBalancer() {
        return slaveBalancer;
    }

    public void setSlaveBalancer(Class<? extends DataSourceLoadBalancer> slaveBalancer) {
        this.slaveBalancer = slaveBalancer;
    }

    public Properties getGlobalDruidConfig() {
        return globalDruidConfig;
    }

    public void setGlobalDruidConfig(Properties globalDruidConfig) {
        this.globalDruidConfig = globalDruidConfig;
    }

    public Properties getGlobalHikariConfig() {
        return globalHikariConfig;
    }

    public void setGlobalHikariConfig(Properties globalHikariConfig) {
        this.globalHikariConfig = globalHikariConfig;
    }

    public String getMasterPerfix() {
        return masterPerfix;
    }

    public void setMasterPerfix(String masterPerfix) {
        this.masterPerfix = masterPerfix;
    }

    public Map<String, Properties> getConfig() {
        return config;
    }

    public void setConfig(Map<String, Properties> config) {
        this.config = config;
    }


}
